<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="/WEB-INF/tlds/shiro.tld" %>

<%@include file="/WEB-INF/views/include/inc.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/views/include/head.jsp"%>
 
<!-- jqgrid-->
<link
	href="<%=contextPath%>/assets/hplus/css/plugins/jqgrid/ui.jqgridffe4.css?0820"
	rel="stylesheet">
	<link
	href="<%=contextPath%>/assets/contextmenu/context.standalone.css"
	rel="stylesheet">
<style type="text/css">
.ui-jqgrid .ui-pg-selbox, .ui-jqgrid .ui-jqgrid-toppager .ui-pg-selbox {
	padding: 0 0 3px 3px;
}
</style>
</head>
<body >
	<div class="animated" >
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox " style="margin-bottom: 0px;">
					<div class="ibox-title" style="border-color: white;">
						 <div class="row">
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input id="keyword" type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> </span>
                                </div>
                            </div>
                            <shiro:hasPermission name="sys:resource:add">  
                            <div class="col-sm-3">
                            <a id="add_btn" type="button" class="btn btn-sm btn-success">新增</a> </span>
                       		</div>
                       		</shiro:hasPermission>
                        </div>
					</div>
					<div class="ibox-content">

						<div class="jqGrid_wrapper">
							<table id="table_list"></table>
							<div id="pager_list_2"></div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 全局js -->
	<%@include file="/WEB-INF/views/include/foot.jsp"%>
	<!-- Peity -->
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/peity/jquery.peity.min.js"></script>

	<!-- jqGrid -->
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>

	<!-- 自定义js -->
	<script
		src="<%=contextPath%>/assets/contextmenu/context.js"></script>

	<!-- Page-Level Scripts -->
	<script>
		$(document).ready(function() {
			$.jgrid.defaults.styleUI = "Bootstrap";
			//初始化右键菜单
			context.init({preventDoubleContext: false});
			$("#table_list").jqGrid({
				url: '<%=contextPath%>/sys/resource/listData',
				ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
				datatype : "json",
				
				autowidth : true,
				shrinkToFit : true,
				mtype : "get",
				rowNum : 20,
				colNames : ["id", "资源名","资源类型","链接地址","权限","是否显示", "描述"],
				colModel : [{
					name : "id",
					index : "id",
					hidden:true
				}, {
					name : "name",
					index : "name",
					width : 90
				}, {
					name : "type",
					index : "type",
					width : 90
				}, {
					name : "href",
					index : "href",
					width : 90
				}, {
					name : "permission",
					index : "permission",
					width : 90
				}, {
					name : "display",
					index : "display",
					width : 90
				}, {
					name : "description",
					index : "description",
					width : 50
				}],
				 treeReader : {  
				      level_field: "level",  
				      parent_id_field: "parent",   
				      leaf_field: "leaf",  
				      expanded_field: "expanded"  
				    },  
			    jsonReader: {      
			        root: "rows",    
			        repeatitems : false      
			      },   
				ExpandColumn: "name",
				treeGrid: true,
				height : $(window).height() - 130,
				treeGridModel: "adjacency"
			});
			
			$(window).bind("resize", function() {
				var b = $(".jqGrid_wrapper").width();
				$("#table_list").setGridWidth(b);
				$("#table_list").setGridHeight($(window).height() - 130);
			})

			
			<shiro:hasPermission name="sys:resource:add">  
			$("#add_btn").click(function(){
				  var isConfirm = true;
				    parent.layer.open({
			        	title:'新增资源',
			            type: 2,
			            fix:true,
			            end :function(){
			        	    if(isConfirm){
			        	    	$("#table_list").trigger("reloadGrid");
			        	    }
			            },
	 			        cancel:function(index){
	 			        	isConfirm = false;
	 			        },
			            area: ['80%','80%'],
			            content: '<%=contextPath%>/sys/resource/addView'
			        });
			})
			</shiro:hasPermission>
			
		
			$("#find_btn").click(function(){ 
		        var keyword = escape($("#keyword").val()); 
		        $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'keyword':keyword}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		    }); 
			<shiro:hasAnyPermission name="sys:resource:update,sys:resource:delete"> 
			//对表格设置右键菜单
			context.attach('#table_list', [
			<shiro:hasPermission name="sys:resource:update">  
          		{
          			text: '修改',
          			action:function(){
          				var selectedIds = $("#table_list").jqGrid("getGridParam", "selrow");
       				    var rowData = $("#table_list").jqGrid("getRowData",selectedIds);
       				    var isConfirm = true;
       				    parent.layer.open({
	 			        	title:'修改资源',
	 			            type: 2,
	 			            fix:true,
	 			            end :function(){
	 			        	    if(isConfirm){
	 			        	    	$("#table_list").trigger("reloadGrid");
	 			        	    }
	 			            },
		 			        cancel:function(index){
		 			        	isConfirm = false;
		 			        },
	 			            area: ['80%','80%'],
	 			            content: '<%=contextPath%>/sys/resource/updateView?id='+rowData.id
	 			        });    
          			}
          		}
          		</shiro:hasPermission>
          		<shiro:hasPermission name="sys:resource:delete">  
          		,
          		{text: '删除',
          			action:function(){
          				parent.swal({
          			        title: "您确定要删除这条信息吗",
          			        text: "删除后将无法恢复，请谨慎操作！",
          			        type: "warning",
          			        showCancelButton: true,
          			        confirmButtonColor: "#DD6B55",
          			        confirmButtonText: "删除",
          			        closeOnConfirm: true
          			    }, function () {
          			    	var selectedIds = $("#table_list").jqGrid("getGridParam", "selrow");
           				    var rowData = $("#table_list").jqGrid("getRowData",selectedIds);
	           				 $.ajax({url:"<%=contextPath%>/sys/resource/delete?id="+rowData.id,
	           						 dataType:'json',
	           						 success:function(data){
	           							if(data.code==200){
	               				    		$("#table_list").trigger("reloadGrid");
	               				    	}else{
	               				    		
	               				    	}
	           						 },
	           						error:function(XMLHttpRequest, textStatus, errorThrown){
	           						 	parent.swal("错误", "删除失败，请重试！", "error");
	           						}
	           				 });
          			    });
          			}
          		}
          		</shiro:hasPermission>
          		]
          	);
			</shiro:hasAnyPermission>
		});
	</script>

</body>
</html>

